/**
 * Software Analysis and Verification 
 * @project: Verify Pattern Matching with Guards in Scala
 * @authors: Mirco Dotta and Philippe Suter
 */


package ch.epfl.lara.patterns.scalac

import scala.tools.nsc._
import scala.tools.nsc.transform._
import scala.tools.nsc.plugins._

/** A sample transform.
 */
class PatternMatchingTransform(val global: Global) extends PluginComponent {
  // inherits abstract value `global' and class `Phase' from Transform

  import global._                  // the global environment
  import definitions._             // standard classes and methods
  import typer.{typed, atOwner}    // methods to type trees
  import posAssigner.atPos         // for filling in tree positions 

  /** the following two members override abstract members in            Transform */
  override val phaseName: String = "pattern-matching-analyzer"
  override val runsAfter: String = "refchecks"
  
  def newPhase(prev: Phase) = new MyPhase(prev)
  
 class MyPhase(prev: Phase) extends Phase(prev) {
    def name = phaseName;

    def doStuff(unit: CompilationUnit) {
        Console.println("called on " + unit)
       // important ! unit.body is the tree representing the file       (compilation unit)
       
        Console.println("The tree looks like: \n" + unit.body)
    }
  
    def run {
        currentRun.units.foreach(doStuff)
        Console.println("Our cool phase was run. How exciting.");
    }
  }
}